#include "BattBank.h"

#include "BatteryState.h"
#include "BattStack.h"

//获取英文名称(主要供调试用)
QString CBattBank::GetNameOfBankState()
{
    return CBatteryState::GetName((int)this->usBankState);
}

//获取电池组状态的中文utf8(主要供界面显示)
QString CBattBank::GetUtf8OfBankState()
{
    return CBatteryState::GetUtf8((int)this->usBankState);
}

//是不是禁止状态
bool CBattBank::IsForbidOfBankState()
{
    return CBatteryState::IsForbid((int)this->usBankState);
}

//是不是禁充状态
bool CBattBank::IsForbidChargeOfBankState()
{
    return CBatteryState::IsForbidCharge((int)this->usBankState);
}

//是不是禁访状态
bool CBattBank::IsForbidDischargeOfBankState()
{
    return CBatteryState::IsForbidDischarge((int)this->usBankState);
}

//是不是告警状态
bool CBattBank::IsAlarmOfBankState()
{
    return CBatteryState::IsAlarm((int)this->usBankState);
}

//是不是故障状态
bool CBattBank::IsFaultOfBankState()
{
    return CBatteryState::IsFault((int)this->usBankState);
}

//是不是正常状态
bool CBattBank::IsNormalOfBankState()
{
    return CBatteryState::IsNormal((int)this->usBankState);
}

//是不是预警状态
bool CBattBank::IsWarnOfBankState()
{
    return CBatteryState::IsWarn((int)this->usBankState);
}

//获取Bmu数量
quint16 CBattBank::GetBmuCount()
{
    return qMin(this->usBMUNum, (quint16)MAX_BMU_NUM);
}

//获取支路状态的中文utf8(主要供界面显示)
QString CBattBank::GetUtf8OfBranState()
{
    return CBatteryState::GetUtf8((int)this->usBranState);
}

//计算PACK箱内的单体数量
void CBattBank::CalcSglNumInPack()
{
    usCellNumInPack = 0; //Pack中单体数,默认为0
    if (usPackNumInBank > 0)
    {
        if (0 == (usCellNumInBank % usPackNumInBank))
        {
            //整除
            usCellNumInPack = (quint16) (usCellNumInBank / usPackNumInBank);
        }
        else
        {
            usCellNumInPack = (quint16) ((usCellNumInBank / usPackNumInBank) + 1);
        }
    }
}

//计算PACK箱内的温度数量
void CBattBank::CalcTempNumInPack()
{
    usTempNumInPack = 0; //Pack中温度数,默认为0
    if (usPackNumInBank > 0)
    {
        if (0 == (usTempNumInBank % usPackNumInBank))
        {
            usTempNumInPack = (quint16) (usTempNumInBank / usPackNumInBank);
        }
        else
        {
            usTempNumInPack = (quint16) ((usTempNumInBank / usPackNumInBank) + 1);

        }
    }
}

//计算组簇功率
void CBattBank::CalcBankPower()
{
    //赋值
    if (IsBankVolValid() && IsBankCurValid())
    {
        fBankPower = fBankVol * fBankCur / 1000;
    }
    else
    {
        fBankPower = 0;
    }
}

//初始化为默认值
void CBattBank::InitToDefault()
{
    usBankState = 0xAAAA; //默认为跳机
    usForbidChg = 1;
    usForbidDchg = 1;
    fBankVol = 9999;
    fBankInsuRes = 9999;
    fEnvTemp = -9999; //默认环境温度
    fPosRes = 9999; //正极绝缘电阻
    fNegRes = 9999; //负极绝缘电阻
    fBankSoc = 9999; //组SOC
    usLastTimeSynHour = 9999; //上次对时时数
    uiSendTimeSecs = 9999;
    usSendTimeMsecs = 9999;
    //支路信息
    usBranState = 0xAAAA; //默认为跳机
    fBranInsuRes = 9999; //系统绝缘
}

//初始化单体数据为无效
void CBattBank::InitSglDataToInvalid()
{
    for (int iCellIndex = 0; iCellIndex < MAX_BATT_NUM; ++iCellIndex)
    {
        fSglVol[iCellIndex] = SAMPLE_INVALID_VALUE_UP; //单体电压
        fDtProcSglVol[iCellIndex] = SAMPLE_INVALID_VALUE_UP; //单体电压
        fSglVolTemp[iCellIndex] = SAMPLE_INVALID_VALUE_UP; //单体电压
        fAvgVolTemp = SAMPLE_INVALID_VALUE_UP;
        fSglTemp[iCellIndex] = SAMPLE_INVALID_VALUE_DOWN; //单体温度
        fDtProcSglTemp[iCellIndex] = SAMPLE_INVALID_VALUE_DOWN; //单体温度
        fSglSoc[iCellIndex] = 9999; //单体Soc
        fSglRes[iCellIndex] = 9999; //单体内阻
    }
}

//初始化动力线数据为无效
void CBattBank::InitPwLnDataToInvalid()
{
    for (int iCellIndex = 0; iCellIndex < MAX_PACK_PWR_LN_TEMP_NUM; ++iCellIndex)
    {
        fPwLnTemp[iCellIndex] = SAMPLE_INVALID_VALUE_DOWN; //动力线温度
    }
}

//初始化干节点6和7
void CBattBank::InitDry6And7(CBattStack* pStack)
{
    if (0 == pStack)
    {
        return;
    }

    if (1 == pStack->usPCSDry1Strategy) //配置成 BC 默认状态为 0xAAAA
    {
        if (1 == pStack->usPCSDry1Type) //类型为 保护
        {
            if (6 == pStack->usPCSDry1DONo) //DOA
            {
                if (1 == pStack->usPCSDry1AlarmValue) //常开
                {
                    usDry6Ctrl = 1;
                    iDry6CtrlNum = 3;
                }
                else
                {
                    usDry6Ctrl = 0;
                    iDry6CtrlNum = 3;
                }
            }
            else if (7 == pStack->usPCSDry1DONo) //DOB
            {
                if (1 == pStack->usPCSDry1AlarmValue) //常开
                {
                    usDry7Ctrl = 1;
                    iDry7CtrlNum = 3;
                }
                else
                {
                    usDry7Ctrl = 0;
                    iDry7CtrlNum = 3;
                }
            }
        }
        else
        {
            if (6 == pStack->usPCSDry1DONo) //DOA
            {
                if (1 == pStack->usPCSDry1AlarmValue) //常开
                {
                    usDry6Ctrl = 0;
                    iDry6CtrlNum = 3;
                }
                else
                {
                    usDry6Ctrl = 1;
                    iDry6CtrlNum = 3;
                }
            }
            else if (7 == pStack->usPCSDry1DONo) //DOB
            {
                if (1 == pStack->usPCSDry1AlarmValue) //常开
                {
                    usDry7Ctrl = 0;
                    iDry7CtrlNum = 3;
                }
                else
                {
                    usDry7Ctrl = 1;
                    iDry7CtrlNum = 3;
                }
            }
        }
    }

    if (1 == pStack->usPCSDry2Strategy) //配置成 BC 默认状态为 0xAAAA
    {
        if (1 == pStack->usPCSDry2Type) //类型为 保护
        {
            if (6 == pStack->usPCSDry2DONo) //DOA
            {
                if (1 == pStack->usPCSDry2AlarmValue) //常开
                {
                    usDry6Ctrl = 1;
                    iDry6CtrlNum = 3;
                }
                else
                {
                    usDry6Ctrl = 0;
                    iDry6CtrlNum = 3;
                }
            }
            else if (7 == pStack->usPCSDry2DONo) //DOB
            {
                if (1 == pStack->usPCSDry2AlarmValue) //常开
                {
                    usDry7Ctrl = 1;
                    iDry7CtrlNum = 3;
                }
                else
                {
                    usDry7Ctrl = 0;
                    iDry7CtrlNum = 3;
                }
            }
        }
        else
        {
            if (6 == pStack->usPCSDry2DONo) //DOA
            {
                if (1 == pStack->usPCSDry2AlarmValue) //常开
                {
                    usDry6Ctrl = 0;
                    iDry6CtrlNum = 3;
                }
                else
                {
                    usDry6Ctrl = 1;
                    iDry6CtrlNum = 3;
                }
            }
            else if (7 == pStack->usPCSDry2DONo) //DOB
            {
                if (1 == pStack->usPCSDry2AlarmValue) //常开
                {
                    usDry7Ctrl = 0;
                    iDry7CtrlNum = 3;
                }
                else
                {
                    usDry7Ctrl = 1;
                    iDry7CtrlNum = 3;
                }
            }
        }
    }
}

//初始化故障灯
void CBattBank::InitFaultLamp(int iStackCtrlDoNo)
{
    // 故障灯默认值
    if (1 == iStackCtrlDoNo)
    {
        usDry1Ctrl = 1;
        iDry1CtrlNum = 3;
    }
    else if (2 == iStackCtrlDoNo)
    {
        usDry2Ctrl = 1;
        iDry2CtrlNum = 3;
    }
    else if (3 == iStackCtrlDoNo)
    {
        usDry3Ctrl = 1;
        iDry3CtrlNum = 3;
    }
    else if (4 == iStackCtrlDoNo)
    {
        usDry4Ctrl = 1;
        iDry4CtrlNum = 3;
    }
    else if (5 == iStackCtrlDoNo)
    {
        usDry5Ctrl = 1;
        iDry5CtrlNum = 3;
    }
}

//初始化运行灯
void CBattBank::InitRunLamp(int iStackCtrlDoNo)
{
    // 运行灯默认值
    if (1 == iStackCtrlDoNo)
    {
        usDry1Ctrl = 0;
        iDry1CtrlNum = 3;
    }
    else if (2 == iStackCtrlDoNo)
    {
        usDry2Ctrl = 0;
        iDry2CtrlNum = 3;
    }
    else if (3 == iStackCtrlDoNo)
    {
        usDry3Ctrl = 0;
        iDry3CtrlNum = 3;
    }
    else if (4 == iStackCtrlDoNo)
    {
        usDry4Ctrl = 0;
        iDry4CtrlNum = 3;
    }
    else if (5 == iStackCtrlDoNo)
    {
        usDry5Ctrl = 0;
        iDry5CtrlNum = 3;
    }
}

//初始化降功率信息
void CBattBank::InitDropPowerInfo(CBattStack* pStack)
{
    if (0 == pStack)
    {
        return;
    }

    if (pStack->usDropPowerEnabled > 0)
    {
        fBankAllowMaxChargePower = pStack->fBankMaxChargePower; //电池组最大充电功率             113
        fBankAllowMaxDischargePower = pStack->fBankMaxDischargePower; //电池组最大放电功率             115
        fBankAllowMaxChargeCurrent = pStack->fBankMaxChargeCurrent; //电池组最大充电电流             117
        fBankAllowMaxDischargeCurrent = pStack->fBankMaxDischargeCurrent; //电池组最大放电电流             119

        fLastBankAllowMaxChargePower = pStack->fBankMaxChargePower; //电池组上次最大充电功率
        fLastBankAllowMaxDischargePower = pStack->fBankMaxDischargePower; //电池组上次最大放电功率
        fLastBankAllowMaxChargeCurrent = pStack->fBankMaxChargeCurrent; //电池组上次最大充电电流
        fLastBankAllowMaxDischargeCurrent = pStack->fBankMaxDischargeCurrent; //电池组上次最大放电电流
    }
    else
    {
        fBankAllowMaxChargePower = 0;
        fBankAllowMaxDischargePower = 0;
        fBankAllowMaxChargeCurrent = 0;
        fBankAllowMaxDischargeCurrent = 0;
    }
}

//是否对时成功(true成功,false失败)
bool CBattBank::IsCheckTimeOk()
{
    return (uiSendTimeSecs == uiReceTimeSecs
        && usSendTimeMsecs == usReceTimeMsecs);
}

//计算can通讯帧数
void CBattBank::CalcCanFrameNum(quint16 usPackPowerLineStrategy)
{
    int iTempNum = ((0 == usCellNumInBank % 3) ? (usCellNumInBank / 3) : (usCellNumInBank / 3) + 1) * 2;  // Vol Res
    if (10 == usPackPowerLineStrategy)
	{
        iTempNum += (0 == (usTempNumInBank + usPackNumInBank) % 3) ? ((usTempNumInBank + usPackNumInBank) / 3) : ((usTempNumInBank + usPackNumInBank) / 3) + 1;       // Temp
	}
    else if (usPackPowerLineStrategy > 0)
	{
        iTempNum += (0 == (usTempNumInBank + usPackNumInBank * 2) % 3) ? ((usTempNumInBank + usPackNumInBank * 2) / 3) : ((usTempNumInBank + usPackNumInBank * 2) / 3) + 1;       // Temp
	}
	else
	{
        iTempNum += (0 == usTempNumInBank % 3) ? (usTempNumInBank / 3) : (usTempNumInBank / 3) + 1;       // Temp
	}
    iTempNum += ((0 == usCellNumInBank % 6) ? (usCellNumInBank / 6) : (usCellNumInBank / 6) + 1) * 2; // Soc  Soh
    iTempNum += (0 == usCellNumInBank % 48) ? (usCellNumInBank / 48) : (usCellNumInBank / 48) + 1;    // Dchg Equ State
    iTempNum += (0 == usCellNumInBank % 48) ? (usCellNumInBank / 48) : (usCellNumInBank / 48) + 1;    // Chg Equ State
    iTempNum += (0 == usPackNumInBank % 3) ? (usPackNumInBank / 3) : (usPackNumInBank / 3) + 1;       // Pack Vol
	iTempNum += 17;  // 组端帧 + 最大最小电压温度 + Do 状态 + 总帧 + 心跳 + DI状态 + 环境温度 + BCMU版本 + BC运行模式

    usCanFrameNum = (quint16)iTempNum;
}

bool CBattBank::IsBankVolValid()
{
    return (fBankVol < BANK_VOL_SAMPLE_INVALID_VALUE_UP)
        && (fBankVol > BANK_VOL_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBankVolInvalid()
{
    return !IsBankVolValid();
}

bool CBattBank::IsBankCurValid()
{
    return (fBankCur < BANK_CUR_SAMPLE_INVALID_VALUE_UP)
        && (fBankCur > BANK_CUR_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBankCurInvalid()
{
    return !IsBankCurValid();
}

bool CBattBank::IsBankSocValid()
{
    return (fBankSoc < SOC_SAMPLE_INVALID_VALUE_UP)
        && (fBankSoc > SOC_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBankSocInvalid()
{
    return !IsBankSocValid();
}

bool CBattBank::IsBankSohValid()
{
    return (fBankSoh < SOH_SAMPLE_INVALID_VALUE_UP)
        && (fBankSoh > SOH_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBankSohInvalid()
{
    return !IsBankSohValid();
}

bool CBattBank::IsBranVolValid()
{
    return (fBranVol < BANK_VOL_SAMPLE_INVALID_VALUE_UP)
        && (fBranVol > BANK_VOL_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBranVolInvalid()
{
    return !IsBranVolValid();
}

bool CBattBank::IsBranCurValid()
{
    return (fBranCur < BANK_CUR_SAMPLE_INVALID_VALUE_UP)
        && (fBranCur > BANK_CUR_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBranCurInvalid()
{
    return !IsBranCurValid();
}

bool CBattBank::IsBranSocValid()
{
    return (fBranSoc < SOC_SAMPLE_INVALID_VALUE_UP)
        && (fBranSoc > SOC_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBranSocInvalid()
{
    return !IsBranSocValid();
}

bool CBattBank::IsBranSohValid()
{
    return (fBranSoh < SOC_SAMPLE_INVALID_VALUE_UP)
        && (fBranSoh > SOC_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsBranSohInvalid()
{
    return !IsBranSohValid();
}

bool CBattBank::IsPackVolValid(int iPackIndex)
{
    if (iPackIndex < 0 || iPackIndex >= MAX_PACK_NUM)
    {
        return false;
    }

    return (fPackVol[iPackIndex] < PACK_VOL_SAMPLE_INVALID_VALUE_UP)
        && (fPackVol[iPackIndex] > PACK_VOL_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsPackVolInvalid(int iPackIndex)
{
    return !IsPackVolValid(iPackIndex);
}

bool CBattBank::IsSglVolValid(int iSglIndex)
{
    if (iSglIndex < 0 || iSglIndex >= MAX_BATT_NUM)
    {
        return false;
    }

    return (fSglVol[iSglIndex] < SGL_VOL_SAMPLE_INVALID_VALUE_UP)
        && (fSglVol[iSglIndex] > SGL_VOL_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsSglVolInvalid(int iSglIndex)
{
    return !IsSglVolValid(iSglIndex);
}

bool CBattBank::IsSglTempValid(int iSglIndex)
{
    if (iSglIndex < 0 || iSglIndex >= MAX_BATT_NUM)
    {
        return false;
    }

    return (fSglTemp[iSglIndex] < TMP_SAMPLE_INVALID_VALUE_UP)
        && (fSglTemp[iSglIndex] > TMP_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsSglTempInvalid(int iSglIndex)
{
    return !IsSglTempValid(iSglIndex);
}

bool CBattBank::IsSglSocValid(int iSglIndex)
{
    if (iSglIndex < 0 || iSglIndex >= MAX_BATT_NUM)
    {
        return false;
    }

    return (fSglSoc[iSglIndex] < SOC_SAMPLE_INVALID_VALUE_UP)
        && (fSglSoc[iSglIndex] > SOC_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsSglSocInvalid(int iSglIndex)
{
    return !IsSglSocValid(iSglIndex);
}

bool CBattBank::IsSglSohValid(int iSglIndex)
{
    if (iSglIndex < 0 || iSglIndex >= MAX_BATT_NUM)
    {
        return false;
    }

    return (fSglSoh[iSglIndex] < SOH_SAMPLE_INVALID_VALUE_UP)
        && (fSglSoh[iSglIndex] > SOH_SAMPLE_INVALID_VALUE_DOWN);
}

bool CBattBank::IsSglSohInvalid(int iSglIndex)
{
    return !IsSglSohValid(iSglIndex);
}

QDateTime CBattBank::GetTimeBranChgDropPower()
{
    QDateTime dt(QDate(usBranChgDropPowerYear, usBranChgDropPowerMonth, usBranChgDropPowerDay)
                 , QTime(usBranChgDropPowerHour, usBranChgDropPowerMin, usBranChgDropPowerSec));

    return dt;
}

void CBattBank::SetTimeBranChgDropPower(const QDateTime& dt)
{
    // 支路充电降功率时间
    this->usBranChgDropPowerYear = (quint16)(dt.date().year());
    this->usBranChgDropPowerMonth = (quint16)(dt.date().month());
    this->usBranChgDropPowerDay = (quint16)(dt.date().day());
    this->usBranChgDropPowerHour = (quint16)(dt.time().hour());
    this->usBranChgDropPowerMin = (quint16)(dt.time().minute());
    this->usBranChgDropPowerSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeBranDchgDropPower()
{
    QDateTime dt(QDate(usBranDchgDropPowerYear, usBranDchgDropPowerMonth, usBranDchgDropPowerDay)
                 , QTime(usBranDchgDropPowerHour, usBranDchgDropPowerMin, usBranDchgDropPowerSec));

    return dt;
}

void CBattBank::SetTimeBranDchgDropPower(const QDateTime& dt)
{
    // 支路放电降功率时间
    this->usBranDchgDropPowerYear = (quint16)(dt.date().year());
    this->usBranDchgDropPowerMonth = (quint16)(dt.date().month());
    this->usBranDchgDropPowerDay = (quint16)(dt.date().day());
    this->usBranDchgDropPowerHour = (quint16)(dt.time().hour());
    this->usBranDchgDropPowerMin = (quint16)(dt.time().minute());
    this->usBranDchgDropPowerSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeStart()
{
    QDateTime dt(QDate(usStartYear, usStartMonth, usStartDay)
                 , QTime(usStartHour, usStartMin, usStartSec));

    return dt;
}

void CBattBank::SetTimeStart(const QDateTime& dt)
{
    // 开始充放电时间
    this->usStartYear = (quint16)(dt.date().year());
    this->usStartMonth = (quint16)(dt.date().month());
    this->usStartDay = (quint16)(dt.date().day());
    this->usStartHour = (quint16)(dt.time().hour());
    this->usStartMin = (quint16)(dt.time().minute());
    this->usStartSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeSave()
{
    QDateTime dt(QDate(usSaveYear, usSaveMonth, usSaveDay)
                 , QTime(usSaveHour, usSaveMin, usSaveSec));

    return dt;
}

void CBattBank::SetTimeSave(const QDateTime& dt)
{
    // 数据保存时间
    this->usSaveYear = (quint16)(dt.date().year());
    this->usSaveMonth = (quint16)(dt.date().month());
    this->usSaveDay = (quint16)(dt.date().day());
    this->usSaveHour = (quint16)(dt.time().hour());
    this->usSaveMin = (quint16)(dt.time().minute());
    this->usSaveSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeStateChangeStart()
{
    QDateTime dt(QDate(usStateChangeStartYear, usStateChangeStartMonth, usStateChangeStartDay)
                 , QTime(usStateChangeStartHour, usStateChangeStartMin, usStateChangeStartSec));

    return dt;
}

void CBattBank::SetTimeStateChangeStart(const QDateTime& dt)
{
    // PCS状态 变化开始时间
    this->usStateChangeStartYear = (quint16)(dt.date().year());
    this->usStateChangeStartMonth = (quint16)(dt.date().month());
    this->usStateChangeStartDay = (quint16)(dt.date().day());
    this->usStateChangeStartHour = (quint16)(dt.time().hour());
    this->usStateChangeStartMin = (quint16)(dt.time().minute());
    this->usStateChangeStartSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeLastBankState()
{
    QDateTime dt(QDate(usLastBankStateYear, usLastBankStateMonth, usLastBankStateDay)
                , QTime(usLastBankStateHour, usLastBankStateMin, usLastBankStateSec));

    return dt;
}

void CBattBank::SetTimeLastBankState(const QDateTime& dt)
{
    // 上一次状态记录, PCS状态维持10秒才真正改变状态
    this->usLastBankStateYear = (quint16)(dt.date().year());
    this->usLastBankStateMonth = (quint16)(dt.date().month());
    this->usLastBankStateDay = (quint16)(dt.date().day());
    this->usLastBankStateHour = (quint16)(dt.time().hour());
    this->usLastBankStateMin = (quint16)(dt.time().minute());
    this->usLastBankStateSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeBcmuConnFaultStart()
{
    QDateTime dt(QDate(usBCMUConnFaultStartYear, usBCMUConnFaultStartMonth, usBCMUConnFaultStartDay)
                 , QTime(usBCMUConnFaultStartHour, usBCMUConnFaultStartMin, usBCMUConnFaultStartSec));

    return dt;
}

void CBattBank::SetTimeBCMUConnFaultStart(const QDateTime& dt)
{
    // BC通讯故障开始时间, FaultStrategy=2 时5分钟后,PCS状态转化成 待机
    this->usBCMUConnFaultStartYear = (quint16)(dt.date().year());
    this->usBCMUConnFaultStartMonth = (quint16)(dt.date().month());
    this->usBCMUConnFaultStartDay = (quint16)(dt.date().day());
    this->usBCMUConnFaultStartHour = (quint16)(dt.time().hour());
    this->usBCMUConnFaultStartMin = (quint16)(dt.time().minute());
    this->usBCMUConnFaultStartSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeBmuConnFaultStart()
{
    QDateTime dt(QDate(usBMUConnFaultStartYear, usBMUConnFaultStartMonth, usBMUConnFaultStartDay)
                 , QTime(usBMUConnFaultStartHour, usBMUConnFaultStartMin, usBMUConnFaultStartSec));

    return dt;
}

void CBattBank::SetTimeBMUConnFaultStart(const QDateTime& dt)
{
    // BMU通讯故障开始时间, FaultStrategy=2 时5分钟后,PCS状态转化成 待机
    this->usBMUConnFaultStartYear = (quint16)(dt.date().year());
    this->usBMUConnFaultStartMonth = (quint16)(dt.date().month());
    this->usBMUConnFaultStartDay = (quint16)(dt.date().day());
    this->usBMUConnFaultStartHour = (quint16)(dt.time().hour());
    this->usBMUConnFaultStartMin = (quint16)(dt.time().minute());
    this->usBMUConnFaultStartSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeConfirm()
{
    QDateTime dt(QDate(usConfirmYear, usConfirmMonth, usConfirmDay)
                , QTime(usConfirmHour, usConfirmMin, usConfirmSec));

    return dt;
}

void CBattBank::SetTimeConfirm(const QDateTime& dt)
{
    // 压差 确认时间时间
    this->usConfirmYear = (quint16)(dt.date().year());
    this->usConfirmMonth = (quint16)(dt.date().month());
    this->usConfirmDay = (quint16)(dt.date().day());
    this->usConfirmHour = (quint16)(dt.time().hour());
    this->usConfirmMin = (quint16)(dt.time().minute());
    this->usConfirmSec = (quint16)(dt.time().second());
}

QDateTime CBattBank::GetTimeDropPowerAlarm()
{
    QDateTime dt(QDate(usDropPowerAlarmYear, usDropPowerAlarmMonth, usDropPowerAlarmDay)
                , QTime(usDropPowerAlarmHour, usDropPowerAlarmMin, usDropPowerAlarmSec));

    return dt;
}

void CBattBank::SetTimeDropPowerAlarm(const QDateTime& dt)
{
    // 降功率 - 告警触发时间
    this->usDropPowerAlarmYear = (quint16)(dt.date().year());
    this->usDropPowerAlarmMonth = (quint16)(dt.date().month());
    this->usDropPowerAlarmDay = (quint16)(dt.date().day());
    this->usDropPowerAlarmHour = (quint16)(dt.time().hour());
    this->usDropPowerAlarmMin = (quint16)(dt.time().minute());
    this->usDropPowerAlarmSec = (quint16)(dt.time().second());
}
